package com.niu.config;

import com.niu.interceptor.MyLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author 鹅鹅鹅
 * @Version 1.0.0
 * @Date 2025/7/18 16:49
 * @Description 自定义拦截器的配置类, 配置需要拦截的路径
 */
// @Configuration
public class MyInterceptorConfig implements WebMvcConfigurer {

    // @Autowired
    private MyLoginInterceptor myLoginInterceptor;

    // 注册拦截器方法
    // InterceptorRegistry 注册对象
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 使用注册方法制定需要拦截的路径和排除的路径
        //  /** 拦截任意路径的任意层级  /* 拦截只有一层的任意路径, 与Filter 区分
        registry.addInterceptor(myLoginInterceptor).addPathPatterns("/**").excludePathPatterns("/login");
    }
}
